BX.namespace("BX.UI");if(typeof BX.UI.DialogButtonType==="undefined"){BX.UI.DialogButtonType={undefined:0,accept:1,cancel:2,names:{accept:"accept",cancel:"cancel"}}}if(typeof BX.UI.EditorDialogButton==="undefined"){BX.UI.EditorDialogButton=function(){this._id="";this._type=BX.UI.DialogButtonType.undefined;this._settings={};this._dialog=null;this._keyPressHandler=BX.delegate(this.onKeyPress,this)};BX.UI.EditorDialogButton.prototype={initialize:function(t,i){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=i?i:{};this._type=BX.prop.getInteger(this._settings,"type",BX.UI.DialogButtonType.undefined);this._dialog=BX.prop.get(this._settings,"dialog",null)},bind:function(){if(this._type===BX.UI.DialogButtonType.accept){BX.bind(document,"keydown",this._keyPressHandler)}},unbind:function(){if(this._type===BX.UI.DialogButtonType.accept){BX.unbind(document,"keydown",this._keyPressHandler)}},onKeyPress:function(t){if(this._type!==BX.UI.DialogButtonType.accept){return}t=t||window.event;if(t.keyCode===13){this.onClick(t)}},getId:function(){return this._id},getDialog:function(){return this._dialog},prepareContent:function(){if(this._type===BX.UI.DialogButtonType.accept){return new BX.UI.SaveButton({text:BX.prop.getString(this._settings,"text",this._id),events:{click:BX.delegate(this.onClick,this)}})}else if(this._type===BX.UI.DialogButtonType.cancel){return new BX.UI.CancelButton({text:BX.prop.getString(this._settings,"text",this._id),events:{click:BX.delegate(this.onClick,this)}})}else{return new BX.UI.Button({text:BX.prop.getString(this._settings,"text",this._id),events:{click:BX.delegate(this.onClick,this)}})}},onClick:function(t){var i=BX.prop.getFunction(this._settings,"callback",null);if(i){i(this)}}};BX.UI.EditorDialogButton.create=function(t,i){var e=new BX.UI.EditorDialogButton;e.initialize(t,i);return e}}if(typeof BX.UI.EditorAuxiliaryDialog==="undefined"){BX.UI.EditorAuxiliaryDialog=function(){this._id="";this._settings={};this._popup=null;this._buttons=null};BX.UI.EditorAuxiliaryDialog.prototype={initialize:function(t,i){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=i?i:{}},getSetting:function(t,i){return BX.prop.get(this._settings,t,i)},getId:function(){return this._id},open:function(){this._popup=new BX.PopupWindow(this._id,BX.prop.getElementNode(this._settings,"anchor",null),{autoHide:false,draggable:false,offsetLeft:0,offsetTop:0,zIndex:BX.prop.getInteger(this._settings,"zIndex",0),overlay:BX.prop.getBoolean(this._settings,"overlay",{opacity:20}),bindOptions:{forceBindPosition:true},titleBar:BX.prop.getString(this._settings,"title","No title"),content:BX.prop.getString(this._settings,"content",""),buttons:this.prepareButtons(),events:{onPopupShow:BX.delegate(this.onPopupShow,this),onPopupClose:BX.delegate(this.onPopupClose,this),onPopupDestroy:BX.delegate(this.onPopupDestroy,this)}});this._popup.show();window.setTimeout(function(){this._popup.setClosingByEsc(true)}.bind(this),150)},close:function(){if(this._popup){this._popup.close()}},isOpen:function(){return this._popup&&this._popup.isShown()},prepareButtons:function(){var t=[];this._buttons=[];var i=BX.prop.getArray(this._settings,"buttons",[]);for(var e=0,n=i.length;e<n;e++){var o=i[e];o["dialog"]=this;var s=BX.UI.EditorDialogButton.create(BX.prop.getString(o,"id",""),o);this._buttons.push(s);t.push(s.prepareContent())}return t},bind:function(){for(var t=0,i=this._buttons.length;t<i;t++){this._buttons[t].bind()}},unbind:function(){for(var t=0,i=this._buttons.length;t<i;t++){this._buttons[t].unbind()}},onPopupShow:function(){this.bind()},onPopupClose:function(){this.unbind();if(this._popup){this._popup.destroy()}},onPopupDestroy:function(){if(this._popup){this._popup=null}delete BX.UI.EditorAuxiliaryDialog.items[this.getId()]}};BX.UI.EditorAuxiliaryDialog.items={};BX.UI.EditorAuxiliaryDialog.isItemOpened=function(t){return this.items.hasOwnProperty(t)&&this.items[t].isOpen()};BX.UI.EditorAuxiliaryDialog.hasOpenItems=function(){for(var t in this.items){if(!this.items.hasOwnProperty(t)){continue}if(this.items[t].isOpen()){return true}}return false};BX.UI.EditorAuxiliaryDialog.getById=function(t){return this.items.hasOwnProperty(t)?this.items[t]:null};BX.UI.EditorAuxiliaryDialog.create=function(t,i){var e=new BX.UI.EditorAuxiliaryDialog;e.initialize(t,i);this.items[e.getId()]=e;return e}}if(typeof BX.UI.ConfirmationDialog==="undefined"){BX.UI.ConfirmationDialog=function(){this._id="";this._settings=null;this._confirmListener=BX.delegate(this.onConfirm,this);this._cancelListener=BX.delegate(this.onCancel,this);this._promise=null;this._isOpened=false};BX.UI.ConfirmationDialog.prototype={initialize:function(t,i){this._id=t;this._settings=i?i:{};this._popup=null},getId:function(){return this._id},isOpened:function(){return this._isOpened},open:function(){if(this._isOpened){return this._promise}this._popup=new BX.PopupWindow(this._id,null,{autoHide:false,draggable:true,bindOptions:{forceBindPosition:false},closeByEsc:true,closeIcon:{top:"10px",right:"15px"},zIndex:0,titleBar:BX.prop.getString(this._settings,"title","untitled"),content:BX.prop.getString(this._settings,"content","-"),className:"crm-text-popup",lightShadow:true,events:{onPopupShow:BX.delegate(this.onPopupShow,this),onPopupClose:BX.delegate(this.onPopupClose,this),onPopupDestroy:BX.delegate(this.onPopupDestroy,this)},buttons:[new BX.PopupWindowButton({text:BX.message("JS_CORE_WINDOW_CONTINUE"),className:"popup-window-button-accept",events:{click:this._confirmListener}}),new BX.PopupWindowButtonLink({text:BX.message("JS_CORE_WINDOW_CANCEL"),className:"popup-window-button-link-cancel",events:{click:this._cancelListener}})]});this._popup.show();return this._promise=new BX.Promise},close:function(){if(this._popup){this._popup.close()}},onConfirm:function(){if(this._promise){this._promise.fulfill({cancel:false});this._promise=null}this.close()},onCancel:function(){if(this._promise){this._promise.fulfill({cancel:true});this._promise=null}this.close()},onPopupShow:function(){this._isOpened=true},onPopupClose:function(){this._isOpened=false;if(this._popup){this._popup.destroy()}},onPopupDestroy:function(){if(this._popup){this._popup=null}}};BX.UI.ConfirmationDialog.items={};BX.UI.ConfirmationDialog.get=function(t){return this.items.hasOwnProperty(t)?this.items[t]:null};BX.UI.ConfirmationDialog.create=function(t,i){var e=new BX.UI.ConfirmationDialog;e.initialize(t,i);this.items[e.getId()]=e;return e}}
//# sourceMappingURL=dialog.map.js